<!doctype html>
<html lang="en">

<head>
	<title><%= title %></title>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<!-- VENDOR CSS -->
	<link rel="stylesheet" href="assets/vendor/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="assets/vendor/font-awesome/css/font-awesome.min.css">
	<link rel="stylesheet" href="assets/vendor/linearicons/style.css">
	<!-- MAIN CSS -->
	<link rel="stylesheet" href="assets/css/main.css">
	<!-- FOR DEMO PURPOSES ONLY. You should remove this in your project -->
	<link rel="stylesheet" href="assets/css/demo.css">
	<!-- GOOGLE FONTS -->
	<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700" rel="stylesheet">
	<!-- ICONS -->
	<link rel="apple-touch-icon" sizes="76x76" href="assets/img/apple-icon.png">
	<link rel="icon" type="image/png" sizes="96x96" href="assets/img/favicon.png">
	<script src="/BackStage/js/jquery-1.8.3.js"></script>
</head>

<body>
	<!-- WRAPPER -->
	<div id="wrapper">
		<!-- NAVBAR -->
		<!-- 头部开始 -->
	<%- include top %>
	<!-- 头部结束 -->
		<!-- END NAVBAR -->
		<!-- LEFT SIDEBAR -->
		<!-- 左侧菜单开始 -->
		<%- include left %>
		<!-- 左侧菜单结束 -->
		<!-- END LEFT SIDEBAR -->
		<!-- MAIN -->
		<div class="main">
			<!-- MAIN CONTENT -->
			<div class="main-content">
				<div class="container-fluid" id="inboxmail">
					<!-- 信箱的容器 -->
				</div>
			</div>
			<!-- END MAIN CONTENT -->
		</div>
		<!-- END MAIN -->
		<div class="clearfix"></div>
		<footer>
			<div class="container-fluid">
				<!-- <p class="copyright">Copyright &copy; 2017.Company name All rights reserved.More Templates <a href="http://www.cssmoban.com/" target="_blank" title="模板之家">模板之家</a> - Collect from <a href="http://www.cssmoban.com/" title="网页模板" target="_blank">网页模板</a></p> -->
			</div>
		</footer>
	</div>
	<!-- END WRAPPER -->
	<!-- Javascript -->
	<script src="assets/vendor/jquery/jquery.min.js"></script>
	<script src="assets/vendor/bootstrap/js/bootstrap.min.js"></script>
	<script src="assets/vendor/jquery-slimscroll/jquery.slimscroll.min.js"></script>
	<script src="assets/scripts/klorofil-common.js"></script>
	<script>
		function details(){
			// 详情
			alert('详情页');
		}
		function showinbox(state){
			// 显示信息
			var staffNo = document.getElementById('staffNo').innerText;
			// alert('staffNo');
			var hp = new XMLHttpRequest();
            hp.open('get','/message/unreadHint?mailState='+state+'&addStaffNo='+staffNo,true);
            hp.send();
            hp.onreadystatechange = function(){
				// alert('da');
                if(hp.status == 200){
                    if(hp.readyState == 4){
                        //如果有，那么就插入到消息栏中，如果没有，就取消小红点，
						var datas = eval("("+hp.responseText+")");
						// var des = datas[i].mailContant.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
						// var conntant = datas[i].mailContant.split('\n').map(function(item) {return (<span>{item}<br/></span>)});
						// alert(des);
						// alert(hp.responseText);
						if(state==0){
							var str = "<h3 class='page-title'>收信箱-未读消息</h3>";
						}else if(state==1){
							var str = "<h3 class='page-title'>收信箱-已读消息</h3>";
						}else if(state==2){
							var str = "<h3 class='page-title'>收信箱-回收站</h3>";
						}
                        if(datas.length !=0){
                            myhindicon.innerHTML="&nbsp";
                            for(var i=0;i<datas.length;i++){
								str +="<div class='row'></div>"+
									"<div class='col-md-8'>"+
										"<div class='panel panel-headline'  style='cursor:pointer'>"+
											"<div class='panel-heading'>"+
												"<h3 class='panel-title'>邮件标题:&nbsp;&nbsp;"+datas[i].mailtitle+"</h3>"+
												"<p class='panel-subtitle'>发信人:&nbsp;&nbsp;"+datas[i].staffName+"</p>"+
												"<p class='panel-subtitle'>发送时间:&nbsp;&nbsp;"+datas[i].sendTime+"</p>";
												str+="<span class='panel-subtitle'><input type='checkbox' onclick='takeaway(this);' /><span style='display:none;'>"+datas[i].receiveNo;
													if(state==0){
														str+="</span><i>&nbsp;&nbsp;标记为已读</i></span>";
													}else if(state==1){
														str+="</span><i>&nbsp;&nbsp;移到回收站</i></span>";
													} if(state==2){
														str+="</span><i>&nbsp;&nbsp;彻底删除</i></span>";
													}
													// str+="</span><i>&nbsp;&nbsp;标记为已读</i></span>";
											str+="</div>"+
											"<div class='panel-body'>"+
												"<p>邮件内容:<br/>&nbsp;&nbsp;p"+datas[i].mailContant+"</p>"+
												"<img style='max-width:500px;' src='"+datas[i].mailPicture+"' alt='配图'></img>"+
											"</div>"+
										"</div>"+
									"</div>"+
								"</div>";
                            }
							$('#inboxmail').html(str);
                        }else if(datas.length == 0){
							if(state==0){
								var str = "<h3 class='page-title'>您没有未读消息</h3>";
							}else if(state==1){
								var str = "<h3 class='page-title'>您没有已读消息</h3>";
							} if(state==2){
								var str = "<h3 class='page-title'>回收站为空</h3>";
							}
							$('#inboxmail').html(str);
                        }
                       
                    }
                }
            }
		}
		// 移动邮件
		function takeaway(thischeckbox){
			// $(thischeckbox).next('span').text();
			var hp = new XMLHttpRequest();
            hp.open('get','/message/takeaway?receiveNo='+$(thischeckbox).next('span').text(),true);
            hp.send();
            hp.onreadystatechange = function(){
				if(hp.status == 200){
                    if(hp.readyState == 4){
						var datas = eval("("+hp.responseText+")");
						// alert(hp.responseText);
						if(datas.result=='succeed'){
							showinbox(0);
						}
					}
				}
			}
		}

		// 从地址栏抓取url
		function GetQueryString(name)
		{
			var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if(r!=null)return  unescape(r[2]); return null;
		}

		//启动信箱
		$().ready(function(){
			showinbox(GetQueryString("mailState"));
			// startmail();
		});
		// function startmail(){
		// 	alert(GetQueryString("mailState"));
		// 	showinbox(GetQueryString("mailState"));
		// }
	</script>
</body>

</html>
